Web Front End Note
Meow King February 22, 2024 Updated: February 22, 2024 #web #front-endNuxt && Vue
- Use function as
useFetch
parameter to watch URL change:
/* Same as:
const { data: product, pending, error } = await useAsyncData(() => {
return $fetch(`https://dummyjson.com/products/${id.value}`)
}, {
watch: [id]
})
*/
JavaScript & TypeScript
Add a asynchronous function to event listener
use void
to make the promise void (or you can use catch
);
"click",;
TypeScript
Configuration
Make window
object available:
tsconfig.json
:
"typeRoots": ,
then in one ts file inside the file path, do things like this:
;
;
declare global
Catch Error Type
try catch error
JSON
How to Cast a JSON Object to a Class in TypeScript
You can combine the above approaches with type guard function
like this one
The one that I'm currently using:
static json: unknown : State | null
Destructure a method from an object.
Instead of doing
;
Do this:
// const { decode_range } = XLSX.utils;
;
Since the first may cause unintentional scoping of this
according to eslint:
error Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead @typescript-eslint/unbound-method